package jd.client.get;

import jd.client.Response;
import jd.client.exception.ResponseParseException;

/**
 * @author Denis Migol
 * 
 */
public class GetDownloadStatusResponse extends Response {

	public static final int RUNNING = 0;
	public static final int NOT_RUNNING = 1;
	public static final int STOPPING = 2;

	private Integer status;

	@Override
	public Response parse(final String response) throws ResponseParseException {
		status = parseStatus(response);
		return super.parse(response);
	}

	private Integer parseStatus(final String string) throws ResponseParseException {
		final String s;
		try {
			s = string.trim();
		} catch (final Exception e) {
			throw new ResponseParseException("Couldn't parse status: " + string);
		}
		if ("RUNNING".equals(s)) {
			return RUNNING;
		} else if ("NOT_RUNNING".equals(s)) {
			return NOT_RUNNING;
		} else if ("STOPPING".equals(s)) {
			return STOPPING;
		}
		throw new ResponseParseException("Couldn't parse status: " + s);
	}

	/**
	 * @param status
	 *            the status to set
	 */
	protected void setStatus(final Integer status) {
		this.status = status;
	}

	/**
	 * @return the status
	 */
	public Integer getStatus() {
		return status;
	}

}
